package com.example.votesystem.service;

import com.example.votesystem.dao.TItemMapper;
import com.example.votesystem.pojo.TItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CheckItemService {
    @Autowired
    private TItemMapper tItemMapper;

    public void add(Integer id, String name, String headUrl) {
        TItem tItem = new TItem();
        tItem.setName(name);
        tItem.setHeadurl(headUrl);
        tItem.setContact(id);
        tItemMapper.insert(tItem);
    }

    public void update(TItem tItem) {
        tItemMapper.updateById(tItem);
    }

    public List<TItem> findAll() {
        return tItemMapper.findAll();
    }

    public void delete(Integer[] roleIdsss) {
        if (!StringUtils.isEmpty(roleIdsss))
            for (int i = 0; i < roleIdsss.length; i++) {
                Integer id = roleIdsss[i];
                tItemMapper.deleteById(id);
            }
    }
}
